<?php
class Zenddn_System_Auth{
    
    public function login($params = array(), $options = null){
        $username = $params['username'];
        $password = sha1($params['password']);
            
    	$db = Zend_Registry::get('db');
    	$auth = Zend_Auth::getInstance();
        
        $authAdapter = new Zend_Auth_Adapter_DbTable($db);
        $authAdapter->setTableName("users")
                    ->setIdentityColumn('username')
                    ->setCredentialColumn('password')
                    ->setIdentity($username)
                    ->setCredential($password)
                    ->getDbSelect()->where("status = ?", 1)->where("deleted = ?", 0);
                    
        $result = $auth->authenticate($authAdapter);
        
        $isLogin = false;
        
        if($result->isValid()){
            $returnColumns = array('id', 'name', 'username', 'email', 'user_group', 'role');
                        
            $data = $authAdapter->getResultRowObject($returnColumns);
            
            $auth->getStorage()->write($data);
            
            $isLogin = true;
        }
        
        return $isLogin;
    }
}